package com.example.mall.web.controller;

import com.example.mall.domain.SpendingReductionActivities;
import com.example.mall.dto.SpendingReductionActivitiesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SpendingReductionActivitiesQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISpendingReductionActivitiesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/spendingReductionActivities")
public class SpendingReductionActivitiesController {

    @Autowired
    public ISpendingReductionActivitiesService spendingReductionActivitiesService;

    /**
     * 分页查询满减活动表信息
     * @param spendingReductionActivitiesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询满减活动表信息",notes = "分页查询满减活动表信息",httpMethod = "GET")
    public JSONResult queryPage(SpendingReductionActivitiesQuery spendingReductionActivitiesQuery){
        PageDTO<SpendingReductionActivitiesDto> spendingReductionActivitiesDtoPageDTO = spendingReductionActivitiesService.queryPage(spendingReductionActivitiesQuery);
        return JSONResult.success("查询成功",spendingReductionActivitiesDtoPageDTO);
    }

    /**
     * 根据id查询满减活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("query/{activityId}")
    @ApiOperation(value = "根据id查询满减活动表信息",notes = "根据id查询满减活动表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SPENDING_REDUCTION_ACTIVITYID_NOT_ID);
        }
        SpendingReductionActivities spendingReductionActivities = spendingReductionActivitiesService.getById(activityId);
        return JSONResult.success("查询成功",spendingReductionActivities);
    }

    /**
     * 根据id查询满减活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("querySpendingReductionActivitiesById/{activityId}")
    @ApiOperation(value = "根据id查询满减活动表信息",notes = "根据id查询满减活动表信息",httpMethod = "GET")
    public JSONResult querySpendingReductionActivitiesById(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SPENDING_REDUCTION_ACTIVITYID_NOT_ID);
        }
        SpendingReductionActivities spendingReductionActivities = spendingReductionActivitiesService.querySpendingReductionActivitiesById(activityId);
        return JSONResult.success("查询成功",spendingReductionActivities);
    }

    /**
     * 查询全部满减活动表信息
     * @param
     * @return
     */
    @GetMapping("querySpendingReductionActivitiesList")
    @ApiOperation(value = "查询全部满减活动表信息",notes = "查询全部满减活动表信息",httpMethod = "GET")
    public JSONResult querySpendingReductionActivitiesList(){
        List<SpendingReductionActivities> spendingReductionActivities = spendingReductionActivitiesService.querySpendingReductionActivitiesList();
        return JSONResult.success("查询成功",spendingReductionActivities);
    }

    /**
     * 新增满减活动表
     * @param spendingReductionActivitiesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增满减活动表",notes = "新增满减活动表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SpendingReductionActivitiesDto spendingReductionActivitiesDto){
        spendingReductionActivitiesService.insert(spendingReductionActivitiesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改满减活动表信息
     * @param spendingReductionActivitiesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改满减活动表信息",notes = "修改满减活动表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SpendingReductionActivitiesDto spendingReductionActivitiesDto){
        spendingReductionActivitiesService.update(spendingReductionActivitiesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除满减活动表信息
     * @param activityId
     * @return
     */
    @PostMapping("delete/{activityId}")
    @ApiOperation(value = "删除满减活动表信息",notes = "删除满减活动表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activityId") Long activityId) {
        spendingReductionActivitiesService.delete(activityId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除满减活动表信息
     * @param activityIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除满减活动表信息",notes = "批量删除满减活动表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> activityIds) {
        spendingReductionActivitiesService.deleteBatch(activityIds);
        return JSONResult.success("批量删除成功");
    }
}
